import { Module, Global } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { WinstonService } from './winston.service';

/**
 * Winston 日志库模块
 * 基于 NestJS 官方示例实现
 * 参考: https://docs.nestjs.cn/fundamentals/dependency-injection
 * 对应 Java: 日志配置
 */
@Global()
@Module({
  imports: [ConfigModule],
  providers: [
    {
      provide: WinstonService,
      useFactory: (configService: ConfigService) => {
        const winstonConfig = configService.get('winston');
        return new WinstonService(winstonConfig);
      },
      inject: [ConfigService],
    },
  ],
  exports: [WinstonService],
})
export class WinstonModule {}
